#include "parity_check.h"
#include <opencv2/opencv.hpp>

using namespace cv;

int parity_check(const unsigned char* msg, const int msg_length) {
    if (msg == nullptr || msg_length <= 0) {
        return 0;
    }

    Mat mat_msg(1, msg_length, CV_8UC1, const_cast<unsigned char*>(msg));
    int count = countNonZero(mat_msg);
    return (count % 2 == 0) ? 1 : 0;
}